<html>
<head>
    <title>双预防系统</title>
    <link rel="stylesheet" href="../../../assets/bundle.element.css">
    <link rel="stylesheet" href="../../../style.css">

    <style>
        body {
            background: #F0F2F6;
        }

        .main-head {
            background: #fff;
            padding-left: 10px;
            padding-top: 10px;
            margin-bottom: 0px;
            border: solid 1px #fff;
        }

        .chart-outer {
            height: 200px;
        }

        .inputW {
            width: 150px;
        }

        .itemW {
            width: 200px;
        }

        .formLabelWidth {
            width: 100px;
        }

        input {
            BORDER-TOP-STYLE: none;
            BORDER-RIGHT-STYLE: none;
            BORDER-LEFT-STYLE: none;
            /*BORDER-BOTTOM-STYLE: solid*/
        }
    </style>
</head>
<body>
<div class="page" id="page-monitor">
    <div class="page-title">学校安全基本情况统计表</div>
    <div class="page-main">
        <el-row>
            <el-col :span="24">
                <div class="main-head">
                    <el-form :inline="true" size="small">
                        <el-form-item label="课程名称">
                            <el-input v-model="className" autocomplete="off" class="itemW"
                                      placeholder="课程名称"></el-input>
                        </el-form-item>
                        <el-form-item label="" prop="startTime">
                            <el-col :span="11">
                                <el-date-picker type="date" placeholder="开始时间" v-model="startTime"
                                                value-format="yyyy-MM-dd" style="width: 100%;"></el-date-picker>
                            </el-col>
                            <el-col class="line" :span="2">-</el-col>
                            <el-col :span="11">
                                <el-date-picker type="date" placeholder="结束时间" v-model="endTime"
                                                value-format="yyyy-MM-dd" style="width: 100%;"></el-date-picker>
                            </el-col>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="search">查询</el-button>
                            <el-button type="primary" @click="addBtn">添加</el-button>
                        </el-form-item>
                    </el-form>
                </div>
                <el-table :data="tableData" height="660" :stripe="true" :border="true" size="mini" style="width: 100%">
                    <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
                    <el-table-column prop="className" label="课程名称"></el-table-column>
                    <el-table-column prop="teacher" label="教师"></el-table-column>
                    <el-table-column prop="grade" label="年级">
                        <template slot-scope="scope">
                            <template v-if="scope.row.grade==1">
                                一年级
                            </template>
                            <template v-if="scope.row.grade==2">
                                二年级
                            </template>
                            <template v-if="scope.row.grade==3">
                                三年级
                            </template>
                            <template v-if="scope.row.grade==4">
                                四年级
                            </template>
                            <template v-if="scope.row.grade==5">
                                五年级
                            </template>
                            <template v-if="scope.row.grade==6">
                                六年级
                            </template>
                        </template>
                    </el-table-column>

                    <el-table-column prop="bookVersion" label="教材版本"></el-table-column>
                    <el-table-column prop="bookObject" label="教育对象"></el-table-column>
                    <el-table-column prop="eduPeople" label="教育人数"></el-table-column>
                    <el-table-column prop="eduContent" label="教案"></el-table-column>
                    <el-table-column prop="toSumUp" label="总结"></el-table-column>
                    <el-table-column prop="eduTime" label="培训时间" width="110px">
                        <template slot-scope="scope" v-if="scope.row.eduTime">
                            <el-tag size="medium">{{scope.row.eduTime.replace("T"," ").substr(0,10)}}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="file" label="下载文件">
                        <template slot-scope="scope">
                            <el-button @click="report(scope.row.file)" round size="small" type="primary"
                                       icon="el-icon-download" circle></el-button>
                        </template>
                    </el-table-column>
                    <!--<el-table-column prop="status" label="状态">-->
                    <!--<template slot-scope="scope">-->
                    <!--<template v-if="scope.row.status==0">-->
                    <!--未批示-->
                    <!--</template>-->
                    <!--<template v-if="scope.row.status==1">-->
                    <!--已批示-->
                    <!--</template>-->
                    <!--</template>-->
                    <!--</el-table-column>-->
                    <!--<el-table-column prop="comAontent" label="上级批示"></el-table-column>-->
                    <el-table-column prop="stationName" label="操作" min-width="230px">
                        <template slot-scope="scope">
                            <el-button @click="editClick(scope.row)" round size="small" type="primary"
                                       icon="el-icon-edit" circle></el-button>
                            <!--<el-button icon="el-icon-delete" round size="small"-->
                            <!--@click="removeItem(scope.row.Id)"></el-button>-->
                            <!--<el-button @click="openCommend(scope.row)" round size="small" type="primary"-->
                            <!--icon="el-icon-search" circle></el-button>-->

                            <!--<el-button @click="addcheck(scope.row.Id)" size="small" icon="el-icon-search" circle>-->
                            <!--查看批示-->
                            <!--</el-button>-->
                            <el-button @click="removeItem(scope.row.Id)" round size="small" type="danger"
                                       icon="el-icon-delete" circle></el-button>
                            <!--<el-button @click="removeItem(scope.row.Id)" size="small"-->
                            <!--type="danger" icon="el-icon-delete" circle>-->
                            <!--删除-->
                            <!--</el-button>-->
                        </template>
                    </el-table-column>
                </el-table>
                <div class="page-footer">
                    <el-pagination background layout="prev, pager, next" :pagesize="pagesize" :total="totalCount"
                                   :current-page.sync="pageno" @current-change="onChangePage">
                    </el-pagination>
                </div>
            </el-col>
        </el-row>
        <el-dialog :title="'添加'" :visible.sync="addVisible" width="1000px">
            <el-form :model="addForm" ref="addForm" :inline="true" style="margin-left: 55px">
                <el-form-item label="课程名称" :label-width="120" prop="className" :rules="[
                             {required:true,message:'课程名称!',trigger:'blur'}
                            ]">
                    <el-input v-model="addForm.className" autocomplete="off" class="itemW"
                              placeholder="课程名称"></el-input>
                </el-form-item>

                <el-form-item label="教师" :label-width="120" prop="teacher" :rules="[
                             {required:true,message:'教师!',trigger:'blur'}
                            ]">
                    <el-input v-model="addForm.teacher" autocomplete="off" class="itemW"
                              placeholder="教师"></el-input>
                </el-form-item>

                <el-form-item label="年级" :label-width="120" prop="grade" :rules="[
                             {required:true,message:'年级!',trigger:'blur'}
                            ]">
                    <el-select style="width: 200px;" v-model="addForm.grade">
                        <!--<el-option label="请选择" value=""></el-option>-->
                        <el-option label="一年级" value="1"></el-option>
                        <el-option label="二年级" value="2"></el-option>
                        <el-option label="三年级" value="3"></el-option>
                        <el-option label="四年级" value="4"></el-option>
                        <el-option label="五年级" value="5"></el-option>
                        <el-option label="六年级" value="6"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="教材版本" :label-width="120" prop="bookVersion" :rules="[
                             {required:true,message:'教材版本!',trigger:'blur'}
                            ]">
                    <el-input v-model="addForm.bookVersion" autocomplete="off" class="itemW"
                              placeholder="教材版本"></el-input>
                </el-form-item>
                <el-form-item label="教育对象" :label-width="120" prop="bookObject" :rules="[
                             {required:true,message:'教育对象!',trigger:'blur'}
                            ]">
                    <el-input v-model="addForm.bookObject" autocomplete="off" class="itemW"
                              placeholder="教育对象"></el-input>
                </el-form-item>
                <el-form-item label="教育人数" :label-width="120" prop="eduPeople" :rules="[
                             {required:true,message:'教育人数!',trigger:'blur'}
                            ]">
                    <el-input v-model="addForm.eduPeople" autocomplete="off" class="itemW"
                              placeholder="教育人数" type="number"></el-input>
                </el-form-item>
                <el-form-item label="教案" :label-width="120" prop="eduContent" :rules="[
                             {required:true,message:'教案!',trigger:'blur'}
                            ]">
                    <el-input v-model="addForm.eduContent" autocomplete="off" class="itemW"
                              placeholder="教案"></el-input>
                </el-form-item>
                <el-form-item label="实施时间" :label-width="120" prop="eduTime" :rules="[
                             {required:true,message:'实施时间!',trigger:'blur'}
                            ]">
                    <el-date-picker
                            v-model="addForm.eduTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="实施时间" style="width: 200px">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="总结" :label-width="120" prop="toSumUp" :rules="[
                             {required:true,message:'总结!',trigger:'blur'}
                            ]">
                    <el-input v-model="addForm.toSumUp" autocomplete="off" class="itemW"
                              placeholder="总结"></el-input>
                </el-form-item>


                <el-form-item label="文件上传">
                    <!--iot.hzcando.com-->
                    <el-upload
                            class="upload-demo"
                            drag
                            :action="url+'/api/idm/v1/SchoolSafeTeach/Add'"
                            :headers="headers"
                            name="file"
                            :data="addForm"
                            :limit="1"
                            :auto-upload="false"
                            :on-change="fileChange"
                            :on-success="onSuccess"
                            :on-error="onError"
                            ref="add">
                        <i class="el-icon-upload"></i>
                        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                        <!--<div class="el-upload__tip" slot="tip">只能上传jpg/png文件</div>-->
                    </el-upload>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="addVisible = false">取 消</el-button>
                <el-button type="primary" @click="plan_submit('add')">确 定</el-button>
            </div>
        </el-dialog>
        <el-dialog :title="'编辑'" :visible.sync="editVisible" :show-close="false" style="display: none"
                   width="1000px">
            <el-form :model="editForm" ref="editForm" :inline="true" style="margin-left: 55px">


                <el-form-item label="课程名称" :label-width="120" prop="className" :rules="[
                             {required:true,message:'课程名称!',trigger:'blur'}
                            ]">
                    <el-input v-model="editForm.className" autocomplete="off" class="itemW"
                              placeholder="课程名称"></el-input>
                </el-form-item>

                <el-form-item label="教师" :label-width="120" prop="teacher" :rules="[
                             {required:true,message:'教师!',trigger:'blur'}
                            ]">
                    <el-input v-model="editForm.teacher" autocomplete="off" class="itemW"
                              placeholder="教师"></el-input>
                </el-form-item>

                <el-form-item label="年级" :label-width="120" prop="grade" :rules="[
                             {required:true,message:'年级!',trigger:'blur'}
                            ]">
                    <el-select style="width: 200px;" v-model="editForm.grade">
                        <!--<el-option label="请选择" value=""></el-option>-->
                        <el-option label="一年级" value="1"></el-option>
                        <el-option label="二年级" value="2"></el-option>
                        <el-option label="三年级" value="3"></el-option>
                        <el-option label="四年级" value="4"></el-option>
                        <el-option label="五年级" value="5"></el-option>
                        <el-option label="六年级" value="6"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="教材版本" :label-width="120" prop="bookVersion" :rules="[
                             {required:true,message:'教材版本!',trigger:'blur'}
                            ]">
                    <el-input v-model="editForm.bookVersion" autocomplete="off" class="itemW"
                              placeholder="教材版本"></el-input>
                </el-form-item>
                <el-form-item label="教育对象" :label-width="120" prop="bookObject" :rules="[
                             {required:true,message:'教育对象!',trigger:'blur'}
                            ]">
                    <el-input v-model="editForm.bookObject" autocomplete="off" class="itemW"
                              placeholder="教育对象"></el-input>
                </el-form-item>
                <el-form-item label="教育人数" :label-width="120" prop="eduPeople" :rules="[
                             {required:true,message:'教育人数!',trigger:'blur'}
                            ]">
                    <el-input v-model="editForm.eduPeople" autocomplete="off" class="itemW"
                              placeholder="教育人数" type="number"></el-input>
                </el-form-item>
                <el-form-item label="教案" :label-width="120" prop="eduContent" :rules="[
                             {required:true,message:'教案!',trigger:'blur'}
                            ]">
                    <el-input v-model="editForm.eduContent" autocomplete="off" class="itemW"
                              placeholder="教案"></el-input>
                </el-form-item>
                <el-form-item label="实施时间" :label-width="120" prop="eduTime" :rules="[
                             {required:true,message:'实施时间!',trigger:'blur'}
                            ]">
                    <el-date-picker
                            v-model="editForm.eduTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="实施时间" style="width: 200px">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="总结" :label-width="120" prop="toSumUp" :rules="[
                             {required:true,message:'总结!',trigger:'blur'}
                            ]">
                    <el-input v-model="editForm.toSumUp" autocomplete="off" class="itemW"
                              placeholder="总结"></el-input>
                </el-form-item>


                <el-form-item label="文件上传">
                    <!--iot.hzcando.com-->
                    <el-upload
                            class="upload-demo"
                            drag
                            :action="url+'/api/idm/v1/SchoolSafeTeach/Update'"
                            :headers="headers"
                            name="file"
                            :data="editForm"
                            :limit="1"
                            :auto-upload="false"
                            :on-change="fileChange"
                            :on-success="onSuccess"
                            :on-error="onError"
                            ref="edit">
                        <i class="el-icon-upload"></i>
                        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                        <!--<div class="el-upload__tip" slot="tip">只能上传jpg/png文件</div>-->
                    </el-upload>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="editVisible=false">取消</el-button>
                <el-button @click="plan_esubmit('edit')" type="primary">确定</el-button>
            </div>
        </el-dialog>
        <el-dialog title="批示" :visible.sync="commendVisible" :show-close="false" style="display: none">
            <el-form :model="commend">
                <el-form-item label="批示内容:">
                    <el-input v-model="commend.comAontent" autocomplete="off" type="textarea"></el-input>
                </el-form-item>
                <el-form-item label="批示时间:">
                    <el-date-picker
                            v-model="commend.commendTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="批示时间" style="width: 200px">
                    </el-date-picker>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="commendVisible=false">取消</el-button>
                <el-button @click="Commend_submit()" type="primary">确定</el-button>
            </div>
        </el-dialog>
    </div>
</div>
<script type='text/javascript' src='../../../assets/bundle.js' charset='utf-8'></script>
<script type='text/javascript' src='../../../assets/jquery-1.11.2.min.js' charset='utf-8'></script>
<script type='text/javascript' src='../../../assets/echarts.min.js' charset='utf-8'></script>
<script type='text/javascript' src='../../../js/common.js' charset='utf-8'></script>
<script type='text/javascript' src='../../../js/component.js' charset='utf-8'></script>
<script>
    var vuePage = new Vue({
        el: '#page-monitor',
        data: {
            headers: {
                uid: '',
                token: '',
            },
            commend: {},
            commendVisible: false,
            eduType: '',
            startTime: '',
            endTime: '',
            addVisible: false,
            editVisible: false,
            tableData: [],
            pagesize: 10,
            pageno: 1,
            totalCount: 0,
            addForm: {},
            editForm: {},
            param: {},
            className: '',
            url: SiteConfig.webApiset,
            fileList: []
        },
        created: function () {
            // this.tableData.push({
            //         className: '消防',
            //         teacher: '林老师',
            //         grade: '6',
            //         bookVersion: '1.0',
            //         bookObject: '全体',
            //         eduPeople: '10',
            //         eduContent: '消防器材演示',
            //         toSumUp: '积极参与',
            //         eduTime: '2020-03-13',
            //         file: '/SchoolFile/29c56161c22140a084bcaf06d58c8bcf.xlsx'
            //     },
            //     {
            //         className: '消防',
            //         teacher: '林老师',
            //         grade: '6',
            //         bookVersion: '1.0',
            //         bookObject: '全体',
            //         eduPeople: '10',
            //         eduContent: '消防器材演示',
            //         toSumUp: '积极参与',
            //         eduTime: '2020-03-13',
            //         file: '/SchoolFile/29c56161c22140a084bcaf06d58c8bcf.xlsx'
            //     })
            this.headers = {
                uid: SiteConfig.account.uId,
                token: SiteConfig.account.accessToken
            }
            $('.page').show();
            this.loadData();
        },
        methods: {
            fileChange(file, fileList) {
                this.fileList = fileList;
            },
            onSuccess(res) {
                if (res.state == 0) {
                    this.$message({
                        message: '保存成功！',
                        type: 'success'
                    });
                    // this.$refs['add'].clearFiles();
                    // if (this.$refs['edit']!==undefined) {
                    //     this.$refs['edit'].resetFields();
                    // }
                    // this.$refs['edit'].clearFiles();
                    this.$refs.add.clearFiles();
                    this.fileList = [];
                    this.addVisible = false;
                    this.editVisible = false;
                    this.loadData();
                } else {
                    this.$message({
                        type: 'error',
                        message: '报错!' + res.errMsg
                    });
                }

            },
            onError(err) {
                this.$message({
                    type: 'error',
                    message: '报错!' + err.errMsg
                });
            },
            select_status() {
                this.$forceUpdate();
            },
            Commend_submit() {
                if (!this.commend.comAontent) {
                    this.$message({type: 'error', message: '批示内容不能为空'})
                    return;
                }
                if (!this.commend.commendTime) {
                    this.$message({type: 'error', message: '批示时间不能为空'})
                    return;
                }
                HttpUtil.post('SchoolSafeTeach/commendSubmit', this.commend).success((r) => {
                    if (r.state == 0) {
                        vuePage.$message({
                            type: 'success',
                            message: '提交成功!'
                        });
                        this.commendVisible = false;
                        vuePage.loadData();
                    } else {
                        vuePage.$message.error('提交失败!');
                    }
                })
            },
            openCommend: function (row) {
                this.commend = {};
                this.commendVisible = true;
                this.commend = row;
            },
            editClick(row) {
                this.editForm = Object.assign(this.editForm, row);
                this.editForm.grade = row.grade.toString();
                // this.editForm.eduType = row.eduType.toString();
                // this.editForm.grade = row.grade.toString();

                this.editVisible = true;
            },
            report: function (filename) {
                window.open(SiteConfig.webApiset + filename);
            },
            removeItem: function (id) {
                if (!id) {
                    this.$message({
                        type: 'info',
                        message: 'id为空'
                    });
                    return;
                }
                this.$confirm('此操作将永久删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    center: true
                }).then(() => {
                    HttpUtil.post('SchoolSafeTeach/Delete', {Id: id}).success((r) => {
                        if (r.state == 0) {
                            vuePage.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            vuePage.loadData();
                        } else {
                            vuePage.$message.error('删除失败!');
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            },
            plan_submit(name) {
                if (!this.addForm.className) {
                    this.$message({type: 'error', message: '课程名称不能为空'})
                    return;
                }
                if (!this.addForm.teacher) {
                    this.$message({type: 'error', message: '教师不能为空'})
                    return;
                }
                if (!this.addForm.grade) {
                    this.$message({type: 'error', message: '年级不能为空'})
                    return;
                }
                if (!this.addForm.bookVersion) {
                    this.$message({type: 'error', message: '教材版本不能为空'})
                    return;
                }
                if (!this.addForm.bookObject) {
                    this.$message({type: 'error', message: '教育对象不能为空'})
                    return;
                }
                if (!this.addForm.eduPeople) {
                    this.$message({type: 'error', message: '教育人数不能为空'})
                    return;
                }

                if (!this.addForm.eduContent) {
                    this.$message({type: 'error', message: '教案不能为空'})
                    return;
                }
                if (!this.addForm.eduTime) {
                    this.$message({type: 'error', message: '实施时间不能为空'})
                    return;
                }
                if (!this.addForm.toSumUp) {
                    this.$message({type: 'error', message: '总结不能为空'})
                    return;
                }
                if (this.fileList.length == 0) {
                    this.$message({
                        type: 'info',
                        message: '必须选择文件'
                    });
                    return;
                }
                this.addForm.projectNo = SiteConfig.account.projectNo;
                this.$refs[name].submit();
                this.addVisible = false;
                this.$message({
                    message: '添加成功！',
                    type: 'success'
                });
                this.loadData();
            },
            plan_esubmit(name) {

                if (!this.editForm.className) {
                    this.$message({type: 'error', message: '课程名称不能为空'})
                    return;
                }
                if (!this.editForm.teacher) {
                    this.$message({type: 'error', message: '教师不能为空'})
                    return;
                }
                if (!this.editForm.grade) {
                    this.$message({type: 'error', message: '年级不能为空'})
                    return;
                }
                if (!this.editForm.bookVersion) {
                    this.$message({type: 'error', message: '教材版本不能为空'})
                    return;
                }
                if (!this.editForm.bookObject) {
                    this.$message({type: 'error', message: '教育对象不能为空'})
                    return;
                }
                if (!this.editForm.eduPeople) {
                    this.$message({type: 'error', message: '教育人数不能为空'})
                    return;
                }

                if (!this.editForm.eduContent) {
                    this.$message({type: 'error', message: '教案不能为空'})
                    return;
                }
                if (!this.editForm.eduTime) {
                    this.$message({type: 'error', message: '实施时间不能为空'})
                    return;
                }
                if (!this.editForm.toSumUp) {
                    this.$message({type: 'error', message: '总结不能为空'})
                    return;
                }

                this.editForm.projectNo = SiteConfig.account.projectNo;

                if (this.fileList.length == 0) {
                    HttpUtil.post('SchoolSafeTeach/Update', this.editForm).success((r) => {
                        this.$message({
                            message: '修改成功！',
                            type: 'success'
                        });
                        this.fileList = [];
                        this.editVisible = false;
                        this.loadData();
                    })
                } else {
                    this.$refs[name].submit();
                }

                // this.$refs[name].submit();
                // this.editVisible = false;
                // this.$message({
                //     message: '修改成功！',
                //     type: 'success'
                // });
                // vuePage.loadData();
            },
            onChangePage(page) {
                this.pageno = page;
                this.loadData();
            },
            loadData: function () {
                var param = {};
                if (this.className)
                    param.className = this.className;
                if (this.startTime)
                    param.startTime = this.startTime;
                if (this.endTime)
                    param.endTime = this.endTime;
                if (SiteConfig.account.projectNo)
                    param.projectNo = SiteConfig.account.projectNo;
                param.pageno = this.pageno;
                param.pagesize = this.pagesize;
                HttpUtil.post('SchoolSafeTeach/List', param).success((res) => {
                    vuePage.tableData = res.data;
                    vuePage.totalCount = res.total;
                    this.$set(vuePage.tableData);
                    vuePage.$forceUpdate();
                });
            },
            addBtn: function () {
                this.addForm = {};
                this.addVisible = true;
            },
            search: function () {
                this.loadData();
            },
        },
        mounted: function () {

        }
    });
</script>
</body>
</html>
